﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.Utility;
using YouHP.BLL;

namespace YouHP.Pages.DiseaseHistory
{
    public class DiseaseShowAjax : BasePage
    {
        protected List<DiseaseInfo> DiseaseList = new List<DiseaseInfo>();
        protected int pageIndex = 1;
        protected int DiseaseCount = 0;
        protected int pageCount;
        protected override void ShowPage()
        {
            base.ShowPage();

            DiseaseSearchCondtion cond = new DiseaseSearchCondtion();
            cond.FirstLetter = RequestTools.GetQueryString("firstLetter");

            pageIndex = RequestTools.GetQueryInt("page", 1);

            DiseaseList = DiseaseBLL.Instance.GetDiseaseList(10, pageIndex, cond, out DiseaseCount);


            StringBuilder sb = new StringBuilder();
            sb.Append("<div style=\"padding-left:10px\"><ul>");
            foreach (DiseaseInfo info in DiseaseList)
            {
                sb.Append("<li>" + "<a " + "href=\"#\"" + " onclick=\"sel(" + info.Id + ",");
                sb.Append("\'" + info.Name + "\'");
                sb.Append(");\"" + ">" + info.Name + "</a></li>");


            }
            sb.Append("</ul></div>");

            pageCount = Utils.GetPageCount(DiseaseCount, 10);


            sb.Append("<div class=\"pageing\">共" + DiseaseCount + "种&nbsp;&nbsp;");

            int prepage = pageIndex - 1;
            if (prepage <= 0) prepage = pageIndex;
            sb.Append("<a href=\"#\" onclick=\"getDiseaseList(" + "\'" + cond.FirstLetter + "\'" + "," + prepage + ")\">" + "上一页" + "</a>");


            int nextpage = pageIndex + 1;
            if (nextpage >= pageCount) nextpage = pageCount;
            sb.Append("&nbsp;&nbsp;<a href=\"#\" onclick=\"getDiseaseList(" + "\'" + cond.FirstLetter + "\'" + "," + nextpage + ")\">" + "下一页" + "</a>");

            ResponseXML(sb);
        }

        private void ResponseXML(StringBuilder sb)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/html";
            System.Web.HttpContext.Current.Response.Expires = 0;


            System.Web.HttpContext.Current.Response.Write(sb.ToString());
            System.Web.HttpContext.Current.Response.End();
        }
    }
}
